// pages/auth/index.js
import{ request } from "../../request/index.js";
import regeneratorRuntime from '../../lib/runtime/runtime';
import{login}from "../../utils/asyncWx.js"
Page({
    //获取用户信息
    async handleGetUserInfo(e){
        try {
            //console.log(e);
            //1、获取用户信息
            const{encryptedDate,rawDate,iv,signature}=e.detail;
            //2、获取小程序登录成功后的code值
            const {code} = await login();
            const loginParams = {encryptedDate,rawDate,iv,signature,code}
            console.log(code);
            //3、发送请求获取用户token
            const res = await request({url:"/users/wxlogin",data:loginParams,method:"post"});
            console.log(res);
            //4、把tooken存入缓存中，同时跳转回上一个页面
            //wx.setStorageSync("token", token)
            //获取用户的token(由于没有企业账号，所以就只能设置一个token值)
            wx.setStorageSync("token", 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo');
            wx.navigateBack({
            delta: 1,
            })
        } catch (error) {
            console.log(error);
        }
    }
})